package com.liujit.bms.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liujit.bms.app.domain.model.BlogMemberCollection;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * @Description 博客会员收藏Mapper
 * @Author liujun
 * @Date 2021-07-16 18:15:42
 */
@Mapper
public interface BlogMemberCollectionMapper extends BaseMapper<BlogMemberCollection> {

    /**
     * 添加收藏量
     *
     * @param articleId
     * @return
     * @author: liujun
     * @date: 2021/7/18 11:25 上午
     */
    @Update("update blog_article set like_num = like_num + 1 where id = #{articleId}")
    Integer addLikeNum(Long articleId);

    /**
     * 减少收藏量
     *
     * @param articleId
     * @return
     * @author: liujun
     * @date: 2021/7/18 11:25 上午
     */
    @Update("update blog_article set like_num = like_num - 1 where id = #{articleId} and like_num - 1 > 0")
    Integer reduceLikeNum(Long articleId);

    /**
     * 添加收藏量
     * @param userId
     * @return
     * @author: liujun
     * @date: 2021/7/18 11:28 上午
     */
    @Update("update blog_article set like_num = like_num - 1 where like_num - 1 > 0 and id in (select article_id from blog_member_collection where member_id = #{userId})")
    Integer reduceLikeNumByMemberId(Long userId);
}